package pres.moling.common.http;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

@Data
@Accessors(chain = true)
public class HttpResult<T> {
    /**
     * 请求响应编号
     */
    private Integer code;
    /**
     * 请求响应异常
     */

    private String errMsg;
    /**
     * 请求响应体
     */

    private T data;
    /**
     * 请求响应体(如果是集合)
     */
    private List<? extends T> dataList;

    public static <T> HttpResult success(T data) {
        return new HttpResult<>().setCode(0).setData(data);
    }

    public static HttpResult success() {
        return new HttpResult<>().setCode(0);
    }

    public static <T> HttpResult success(List<T> dataList) {
        return new HttpResult<>().setCode(0).setDataList(dataList);
    }

    public static HttpResult fail(Integer code, String errMsg) {
        return new HttpResult<>().setCode(code).setErrMsg(errMsg);
    }
}
